﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LAMVT_CS.UI
{
    public partial class cal : Form
    {
        public cal()
        {
            InitializeComponent();
        }

        private String pheptoan,so;
        private bool kiemtra= true;
        
        public void Tinh()
        {
            double a;
            double b;
            
            Double.TryParse(txtHienThi.Text, out a); 
        }
        private void btnSo7_Click(object sender, EventArgs e)
        {
            if (kiemtra = false) txtHienThi.Clear();
            txtHienThi.Text = txtHienThi.Text + "7";
        }

        private void btnSo8_Click(object sender, EventArgs e)
        {
            if (kiemtra = false) txtHienThi.Clear();
            txtHienThi.Text = txtHienThi.Text + "8";
        }

        private void btnSo9_Click(object sender, EventArgs e)
        {
            if (kiemtra = false) txtHienThi.Clear();
            txtHienThi.Text = txtHienThi.Text + "9";
        }

        private void btnSo4_Click(object sender, EventArgs e)
        {
            if (kiemtra = false) txtHienThi.Clear();
            txtHienThi.Text = txtHienThi.Text + "4";
        }

        private void btnSo5_Click(object sender, EventArgs e)
        {
            if (kiemtra = false) txtHienThi.Clear();
            txtHienThi.Text = txtHienThi.Text + "5";
        }

        private void btnSo6_Click(object sender, EventArgs e)
        {
            if (kiemtra = false) txtHienThi.Clear();
            txtHienThi.Text = txtHienThi.Text + "6";
        }

        private void btnSo1_Click(object sender, EventArgs e)
        {
            if (kiemtra = false) txtHienThi.Clear();
            txtHienThi.Text = txtHienThi.Text + "1";
        }

        private void btnSo2_Click(object sender, EventArgs e)
        {
            if (kiemtra = false) txtHienThi.Clear();
            txtHienThi.Text = txtHienThi.Text + "2";
        }

        private void btnSo3_Click(object sender, EventArgs e)
        {
            if (kiemtra = false) txtHienThi.Clear();
            txtHienThi.Text = txtHienThi.Text + "3";
        }

        private void btnSo0_Click(object sender, EventArgs e)
        {
            if (kiemtra = false) txtHienThi.Clear();
            txtHienThi.Text = txtHienThi.Text + "0";
        }

        private void btnDau_Click(object sender, EventArgs e)
        {
            if (txtHienThi.Text.Contains("-"))
                txtHienThi.Text = txtHienThi.Text.Replace("-", "");
            else
                txtHienThi.Text = "-" + txtHienThi.Text;
             
        }

        private void btnCham_Click(object sender, EventArgs e)
        {
            if (txtHienThi.Text.Contains(".")) txtHienThi.Text.Replace(".", ".");
            else
                txtHienThi.Text = txtHienThi.Text + ".";

        }

        private void btnChia_Click(object sender, EventArgs e)
        {
            so = txtHienThi.Text;
            txtHienThi.Clear();
            
           // txtHienThi.Text = txtHienThi.Text + "/";

            pheptoan = "/";
            kiemtra = false;
            
        }

        private void btnNhan_Click(object sender, EventArgs e)
        {
            so = txtHienThi.Text;
            txtHienThi.Clear();
            
            txtHienThi.Text = txtHienThi.Text + "*";
            pheptoan = "*";
            kiemtra = false;
        }

        private void btnTru_Click(object sender, EventArgs e)
        {
            so = txtHienThi.Text;
            txtHienThi.Clear();
            
            txtHienThi.Text = txtHienThi.Text + "-";
            pheptoan = "-";
            kiemtra = false;
        }

        private void btnCong_Click(object sender, EventArgs e)
        {
            so = txtHienThi.Text;
            txtHienThi.Clear();
            
            txtHienThi.Text = txtHienThi.Text + "+";
            pheptoan = "+";
            kiemtra = false;
        }

        private void btnBang_Click(object sender, EventArgs e)
        {
            
            if (pheptoan == "/")
            {
                txtHienThi.Text = "" + (Convert.ToDouble(so) / Convert.ToDouble(txtHienThi.Text));
                so = txtHienThi.Text;
            }
        }

       
    }
}
